package com.hongxun.modules.csg.service.impl;

import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

import com.hongxun.modules.csg.dao.CPolePitDao;
import com.hongxun.modules.csg.entity.CPolePitEntity;
import com.hongxun.modules.csg.service.CPolePitService;



@Service("cPolePitService")
public class CPolePitServiceImpl implements CPolePitService {
	@Autowired
	private CPolePitDao cPolePitDao;
	
	@Override
	public CPolePitEntity queryObject(String guid){
		return cPolePitDao.queryObject(guid);
	}
	
	@Override
	public List<CPolePitEntity> queryList(Map<String, Object> map){
		return cPolePitDao.queryList(map);
	}
	
	@Override
	public int queryTotal(Map<String, Object> map){
		return cPolePitDao.queryTotal(map);
	}
	
	@Override
	public void save(CPolePitEntity cPolePit){
		if(cPolePit.getGuid()==null||cPolePit.getGuid().equals("")) {
			cPolePit.setGuid(UUID.randomUUID().toString());
		}
		cPolePitDao.save(cPolePit);
	}
	
	@Override
	public void update(CPolePitEntity cPolePit){
		cPolePitDao.update(cPolePit);
	}
	
	@Override
	public void delete(String guid){
		cPolePitDao.delete(guid);
	}
	
	@Override
	public void deleteBatch(String[] guids){
		cPolePitDao.deleteBatch(guids);
	}

	@Override
	public void insertOrReplaceOrDelete(List<CPolePitEntity> entities) {
		for (CPolePitEntity d : entities) {
			if (d.getPPDatastate().equals("删除")) {
				cPolePitDao.delete(d.getGuid());
			} else {
				CPolePitEntity cPolePitEntity = cPolePitDao.queryObject(d.getGuid());
				if (cPolePitEntity == null) {
					cPolePitDao.save(d);
				} else {
					cPolePitDao.update(d);
				}
			}
		}
	}
	
}
